{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import seaborn as sns; sns.set(color_codes=True)\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import math\n",
    "import random\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<seaborn.axisgrid.FacetGrid at 0x116d6c6a0>"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAhQAAAIUCAYAAABCerXlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGJJJREFUeJzt3X2MnWl93+GvvWPHXmzwyAyOiWiwlHIjxTXQhoQXA0uS\nFa+iaVCpFFAUEpCQSAUoCAIFBJRIKUqaqkI0CLIE0kYVwaxKVhBom8VgCImUJjIu7J3AWlWUOM5k\nGJO1d4z3ZfrHGa8dWJsz/s0zZ87MdUmIOY+P5/lx64z5zPNyzrbl5eUAAFRsn/QAAMD0ExQAQJmg\nAADKBAUAUCYoAICymUkPcNn8/D3rcrvJ7OzNWVy8dz12tSVZ32FZ32FZ32FZ32Gt1/rOze3d9nDb\nt9wRipmZmyY9wqZmfYdlfYdlfYdlfYc16fXdckEBAKw9QQEAlAkKAKBMUAAAZYICACgTFABAmaAA\nAMoEBQBQJigAgDJBAQCUCQoAoExQAABlggIAKBMUAECZoAAAygQFAFAmKACAMkEBAJTNTHoAANhI\nTp1eyImTZzJ/bilz+3bn6JGDOXxo/6TH2vAEBQCsOHV6IceO3/3Q47OLSw89FhXX55QHAKw4cfLM\nqrZzhaAAgBXz55ausf3iOk8yfQQFAKyY27f7Gtt3rfMk00dQAMCKo0cOrmo7V7goEwBWXL7wcnSX\nx8XM7dvlLo8xCQoAuMrhQ/s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v671fXL+RgaE4\nQgHcqKs/sXd7Rh/49LHe+5NXjlD8aJJfvPovrHzK748leXuS/Un+qLX2hHWaFxiQoABu1NHW2g+0\n1rYn+dmMrpX4V621x7TWtiX5LyvbklF8zLTWnpLkeEZHN96Y5KtJ2gRmB9aYUx7AjfqbJB9N8gNJ\n/meS9yW5kOQPM/pl5c+S/OrKc+9I8qkkz0vyR0lOtdbuXXnOp9d3bGAI7vIAVm3lLo939t5vmfAo\nwAbhlAcAUOYIBQBQ5ggFAFAmKACAMkEBAJQJCgCgTFAAAGX/H7186NgArkRtAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x117026da0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#random.seed(42)\n",
    "random.seed(45)\n",
    "#random.seed(44)\n",
    "\n",
    "k = 3\n",
    "sara = [7,1]\n",
    "dea = [10,0]\n",
    "peter = [0, 6]\n",
    "mela = [1, 4]\n",
    "kim = [5,3]\n",
    "helle = [9,9]\n",
    "egle = [2,1]\n",
    "vlad = [4,4]\n",
    "jimmie = [6,8]\n",
    "\n",
    "data = [sara, dea, peter, mela, kim, helle, egle, vlad, jimmie]\n",
    "\n",
    "\n",
    "p = pd.DataFrame(columns=['pets', 'star_wars'], data= data)\n",
    "sns.lmplot(x='pets', y='star_wars', data = p,fit_reg=False, size=7.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def distance(x,y):\n",
    "\n",
    "    dist = 0\n",
    "    for i in range(len(x)):\n",
    "        dist += math.pow((x[i] - y[i]), 2)\n",
    "    return math.sqrt(dist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def generate_centroids(k, data):    \n",
    "    return random.sample(data, k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def add_to_cluster(item, centroids):\n",
    "    return item, min(range(len(centroids)), \n",
    "                     key= lambda i: distance(item, centroids[i]) )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[8, 5]"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def add_vector(i, j):\n",
    "    return [i[k] + j[k] for k in range(len(j))]\n",
    "\n",
    "add_vector(sara, mela)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from functools import reduce\n",
    "\n",
    "def move_centroids(k, kim):\n",
    "    print(\"running\")\n",
    "    centroids = []\n",
    "    for cen in range(k):\n",
    "        centroid = []\n",
    "        \n",
    "        print(cen)\n",
    "        members = [i[0] for i in kim if i[1] == cen]\n",
    "        print(members)\n",
    "        if members:\n",
    "            centroid = [i/len(members) for i in reduce(add_vector, members)]\n",
    "            centroids.append(centroid)\n",
    "        \n",
    "    return centroids\n",
    "        \n",
    "\n",
    "#clusters = list(map(cluster, data))\n",
    "#[print(\"item {} = {}\".format(key[0], key[1])) for key in clusters]\n",
    "#move_centroids(2, clusters)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "def draw_iteration(centroids, iteration):\n",
    "        centroids_points = pd.DataFrame([[centroids[i][0],\n",
    "                                          centroids[i][1], \n",
    "                                          i] for i in range(len(centroids))],\n",
    "                                          columns=['pets', 'star_wars', 'cluster'])\n",
    "        centroids_points[\"cluster\"] = [\"{} centroid\".format(i) \n",
    "                                       for i in range(len(centroids))]\n",
    "        ds = pd.DataFrame(columns = ['pets', 'star_wars', 'cluster'], \n",
    "                          data= [[i[0][0], i[0][1], i[1]] for i in iteration])\n",
    "        full_ds = pd.concat([ds, centroids_points], ignore_index=True)\n",
    "\n",
    "        g = sns.FacetGrid(data=full_ds, size=5,\n",
    "                       hue=\"cluster\",\n",
    "                       hue_order=[0, 1, 2 , \"0 centroid\", \"1 centroid\", \"2 centroid\"],\n",
    "                       palette=[\"b\", \"r\", \"g\", \"b\", \"r\", \"g\"],\n",
    "                       hue_kws={\"s\": [20, 20, 20, 500, 500, 500],\n",
    "                          \"marker\": [\"o\", \"o\", \"o\", \"+\", \"+\", \"+\"]})\n",
    "        g.map(plt.scatter,'pets','star_wars', linewidth=1, edgecolor=\"w\")\n",
    "        g.add_legend()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "centroid [5, 3]\n",
      "centroid [2, 1]\n",
      "centroid [1, 4]\n",
      "weight: inf, new weight: 24.619782623985138\n",
      "running\n",
      "0\n",
      "[[7, 1], [10, 0], [5, 3], [9, 9], [4, 4], [6, 8]]\n",
      "1\n",
      "[[2, 1]]\n",
      "2\n",
      "[[0, 6], [1, 4]]\n",
      "centroid [6.833333333333333, 4.166666666666667]\n",
      "centroid [2.0, 1.0]\n",
      "centroid [0.5, 5.0]\n",
      "weight: 24.619782623985138, new weight: 24.87147255400118\n",
      "clusters found\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[([7, 1], 0),\n",
       " ([10, 0], 0),\n",
       " ([0, 6], 2),\n",
       " ([1, 4], 2),\n",
       " ([5, 3], 0),\n",
       " ([9, 9], 0),\n",
       " ([2, 1], 1),\n",
       " ([4, 4], 0),\n",
       " ([6, 8], 0)]"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAa4AAAFgCAYAAADjF51eAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAH7BJREFUeJzt3X2YnXV95/H3yTwwCcmEgQwSWWDqqt/2cotoraIQRQur\n+AAqLbqu9lIKLVaFdSFU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t3XaFxR4FnUN377AjgHyLiiQepXkkHyOBS\ntzk5Io5u3Nzw96nOZb0sIo5s3Avr2sZrUIVcb0Q8hepGgXdl5sXAD4HoQO2SmuChQnWb+4GPA0cD\nXwQ+BPwC+BLVH2rfBt7TWPY24HNUdyr+B+D7EbG1sczfH9yyJTXLqwrVNRpXFa5o3N9LUpfyUKEk\nqSjOuCRJRXHGJUkqisElSSqKwSVJKorBJUkqisElSSrK/wfFBsqoP3PMyAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1184d5320>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAa4AAAFgCAYAAADjF51eAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XuUnXV97/H3zp4ZJiGZMCGDRA8y9VS/7eqqt3rHIFqo\n4gW8tODx2C6l0mJVOB4uFQVP9EhVUHtKLeqp5lhtPYgiBdGKiloRi65arVrl6xGb4IJQkzBkEjKT\nuWSfP54diDGXHWfv2fPb836tlTV7P/u5fH8zO/OZ3/M8+/erNRoNJEkqxZJuFyBJ0uEwuCRJRTG4\nJElFMbgkSUUxuCRJRenrdgF7bN68fU63Nw4PL2NsbGe7yllwbF+5erltYPsOZmRkRa3N5Yge6nH1\n9dW7XUJH2b5y9XLbwPZp/vVMcEmSFgeDS5JUFINLklQUg0uSVBSDS5JUFINLklQUg0uSVBSDS5JU\nFINLklQUg0uSVBSDS1IxarUafX1LqNUcAnAxM7gkFaG/v87yoUF2TjdYPjRI/4BjCC5WC2Z0eEk6\nkFqtxuCyAS688hY2bBpndM0QV5y7lpnpSRqNOU0soQLZ45K04NXrNbbeN8mGTeMAbNg0zr3bJqnX\nPWW4GBlckha82dkGRx81yOiaIQBG1wyxauUgs7P2thYjTxVKWvAajQaTE1Ncce5a7t02yaqVg0xO\nTHmacJEyuCQVYXpqlpnpSZb21d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qfY+ius78NxExeIhtSrT39awVwH3dKkSV0oPrVqrz7ETE\nU6hOy/SMiHgI8HngTzNzfbfrabfMPDEzn5GZJwHfAf4gM+/pclnt9DXgORFRi4iHAkdShVmvGOPB\nMx73Av1AvXvldMy3m9crAU4FbuliLaLwuwqprh2cEhFfp7oG9Mou19NubwSGgUsjYs+1rlMzs+du\nZOhFmXljRJwIfJPqj8TXZOZsl8tqpz8H1kfELVR3Tb4xM+/vck2dcD7w1xExAPyQ6rS9ushpTSRJ\nRSn9VKEkaZExuCRJRTG4JElFMbgkSUUxuCRJRTG4tGhFxP+JiOO7XYekw2NwaTF7JtXn/yQVxM9x\nqWc0Rzd4C9U4c8dRffD3VcCZwH+j+kPtW8Brms/fCvwYWAtcDJxCNT3H9Zn5lnkuX1KL7HGp1zyJ\nKph+jWpaiguAs4GnZeZjgZ8BF2TmO6hGpH8usJxqRJLHUE1D8sgeHXNP6gmlD/kk7eurzQFtiYiP\nAp8CtgC3RQRUQxP9yz7b3AVMRMStVFOPXJKZk/NXsqTDYY9LvWbv2QGWUA36ek1mPrbZ43oS8Nq9\nN2jOKPBkqrnPjgb+KSIeNU/1SjpMBpd6zdMj4mHNyQ3/gOpa1osi4pjmXFjvay6DKuT6IuJxVBMF\nfjUzLwB+AEQXapfUAk8VqtfcDXwEeBjwBeC9wP3Al6j+UPs28I7mujcCn6WaqfifgO9HxM7mOv8w\nv2VLapV3FapnNO8qXNec30tSj/JUoSSpKPa4JElFscclSSqKwSVJKorBJUkqisElSSqKwSVJKsr/\nB91o1u8uo3WiAAAAAElEQVQ1rwYeAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x11800bc50>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def k_means(k, data):\n",
    "    best_weight = math.inf\n",
    "    \n",
    "    centroids = generate_centroids(k, data)\n",
    "    \n",
    "    while True:   \n",
    "       \n",
    "        [print(\"centroid {}\".format(c)) for c in centroids]\n",
    "        # appoint each point to a cluster\n",
    "        iteration = list([add_to_cluster(item, centroids) for item in data])\n",
    "        \n",
    "        draw_iteration(centroids, iteration)\n",
    "        \n",
    "        new_weight = 0\n",
    "        \n",
    "        # calculate the distance between each item, and its centroid\n",
    "        for i in iteration:\n",
    "            new_weight += distance(i[0], centroids[i[1]])\n",
    "        \n",
    "        # if the new weight we continue otherwise we return.\n",
    "        print(\"weight: {}, new weight: {}\".format(best_weight, new_weight))    \n",
    "        if new_weight < best_weight:\n",
    "            best_weight = new_weight\n",
    "            \n",
    "        else:\n",
    "            print(\"clusters found\")\n",
    "            return iteration\n",
    "\n",
    "        # recalculate centroids\n",
    "        centroids = move_centroids(k, iteration)\n",
    "        \n",
    "    \n",
    "k_means(k, data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.cluster import KMeans\n",
    "\n",
    "k = KMeans()\n",
    "clusters = k.fit(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "KMeans(algorithm='auto', copy_x=True, init='k-means++', max_iter=300,\n",
       "    n_clusters=8, n_init=10, n_jobs=1, precompute_distances='auto',\n",
       "    random_state=None, tol=0.0001, verbose=0)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clusters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method KMeans.score of KMeans(copy_x=True, init='k-means++', max_iter=300, n_clusters=8, n_init=10,\n",
       "    n_jobs=1, precompute_distances='auto', random_state=None, tol=0.0001,\n",
       "    verbose=0)>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clusters.score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
